/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** Borrowed from AzuraStory, thanks guys!
 *
 * @author DestinyFate
 *
 * Bowman 4th Job Advancement
 * 2081300.js
 */

importPackage(net.sf.odinms.client);

var status = 0;
var job;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            if (!(cm.getJob().equals(MapleJob.RANGER) ||
                cm.getJob().equals(MapleJob.SNIPER) ||
                cm.getJob().equals(MapleJob.BOWMASTER) ||
                cm.getJob().equals(MapleJob.CROSSBOWMASTER))) {
                cm.sendOk("Why do you want to see me? There is nothing you want to ask me.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.BOWMASTER)) {
                cm.sendNext("You became the best bowman, #bBowmaster#k. Bow Master can use  #bSharp Eyes#k which can increase the fighting power of colleagues so that it became such an important job.");
                //                cm.sendNext("This is not all about Bow Master. Bow Master is good at a fast battle. It can attack enemies with enormously fast speed and even have great attack power.");
                //                cm.sendNext("Don't forget that it all depends on how much you train.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.CROSSBOWMASTER)) {
                cm.sendNext("You became the best bowman #bCrossbowmaster#k. Crossbowmaster can use  #bSharp Eyes#k which can increase the fighting power of colleagues so that it became such an important job.");
                //                cm.sendNext("This is not all about Crossbowmaster. Each shot of Crossbowmaster is very strong. It can attack many enemies with strong power and may beat off them at once.");
                //                cm.sendNext("Don't forget that it all depends on how much you train.");
                cm.dispose();
                return;
            }
            if (cm.getPlayer().getLevel() >= 120) {
                if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.RANGER)) {
                    cm.sendSimple("You're qualified to be a true bowman. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to BowMaster.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.SNIPER)) {
                    cm.sendSimple("You're qualified to be a true bowman. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to CrossBowMaster.#l\r\n#b#L1#  Let me think for a while.#l");
                } else {
                    cm.sendOk("Hmm...You have too many #bSP#k. You can't make the 4th job advancement with too many SP left.");
                    cm.dispose();
                    return;
                }
            } else {
                cm.sendOk("You're still weak to go to bowman extreme road. If you get stronger, come back to me.");
                return;
            }
        } else if (status == 1) {
            if (selection == 0 && cm.getJob().equals(MapleJob.RANGER)) {
                cm.changeJob(MapleJob.BOWMASTER);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(3120005,0,10); //bow expert
                cm.teachSkill(3121007,0,10); //hammy
                cm.teachSkill(3121002,0,10); //sharp eyes
                cm.sendNext("You became the best bowman, the position of #bBowMaster#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.SNIPER)) {
                cm.changeJob(MapleJob.CROSSBOWMASTER);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(3221006,0,10); //blind
                cm.teachSkill(3220004,0,10); //xbow expert
                cm.teachSkill(3221002,0,10); //sharp eyes
                cm.sendNext("You became the best bowman, the position of #bCrossBowMaster#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else {
                cm.sendOk("You don't have to hesitate....You passed all tests. Whenever you decide, talk to me. If you're ready, I'll let you make the 4th job advancement.");
                cm.dispose();
            }
        }
    }
}